package com.linrui;

import com.linrui.user.interceptor.LoginInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("com.linrui.*.mapper")
@EnableCaching  // 开启spring cache
public class CarAppStart implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(CarAppStart.class, args);
    }

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                //拦截地址
                .addPathPatterns("/**")
                //放行地址
                .excludePathPatterns("/logininfo/**")
                .excludePathPatterns("/wxuser/login/**")
                .excludePathPatterns("/user/register/**")
                .excludePathPatterns("/user/bind/**")
                .excludePathPatterns("/verifyCode/**")
                .excludePathPatterns("/fastDfs")
                .excludePathPatterns("/webjars/**")    //swagger界面相关也要放行
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("2/api-docs")
                .excludePathPatterns("/swagger-ui.html");
    }
}
